<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<tr:document xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:c="http://java.sun.com/jstl/core"
             xmlns:fn="http://java.sun.com/jsp/jstl/functions"
             xmlns:mias="http://www.monsters.inc/mias"
             xmlns:tr="http://myfaces.apache.org/trinidad">
<!-- 
     Everything outside the ui:composition tag will be ignored by Facelets!
-->
<ui:composition>
  <!--
       This composition component will render an input where the user can
       choose an option from a list. Depending on the value of the "type" 
       attribute, the list of options will be rendered as follows:
       - type == 'radio'   - a list of radio buttons
       - type == 'listBox' - a list box
       - type == 'choice'  - a combo box / choice list (with pull down)
       The 'choice' value is the default.
       
       Other attributes:
      - items      should evaluate to an array or list with items, where items
                   can be any bean object
      - itemValue  should be the name of the property of the bean that will contain 
                   the value that will be used when the option is chosen
      - itemLabel  should be the name of the property if the bean that will contain
                   the label that will be shown in the choice list. itemLabel and
                   itemValue may be equal.
      - bean       the bean where the chosen value will be stored
      - id         the name of the property in the bean where the chosen value
                   will be stored. This doubles as ID for this field.
      - readOnly   true or false (default is false)
      - required   true or false (default is false)
       
   -->

  <!--
       The required attribute is optional, if it is omitted, we assume "not
       required" 
  -->
  <c:if test="#{empty required}">
    <c:set var="required" value="false" />
  </c:if>
  <c:if test="#{empty type}">
    <c:set var="type" value="choice" />
  </c:if>
  
  <c:choose>
    <c:when test="#{type == 'radio'}">
	  <tr:selectOneRadio value="#{bean[id]}" id="#{id}" required="#{required}" 
	                     readOnly="#{readOnly}" label="#{msg[id]}:" partialSubmit="#{partialSubmit}" autoSubmit="#{autoSubmit}">
	    <mias:items items="#{items}" itemValue="#{itemValue}" itemLabel= "#{itemLabel}"/>
	  </tr:selectOneRadio>
    </c:when>
    <c:when test="#{type == 'listBox'}">
      <tr:selectOneListbox value="#{bean[id]}" id="#{id}" required="#{required}" 
                         readOnly="#{readOnly}" label="#{msg[id]}:" partialSubmit="#{partialSubmit}" autoSubmit="#{autoSubmit}">
        <mias:items items="#{items}" itemValue="#{itemValue}" itemLabel= "#{itemLabel}"/>
      </tr:selectOneListbox>
    </c:when>
    <c:otherwise> <!-- "choice" is the default type -->
      <tr:selectOneChoice value="#{bean[id]}" id="#{id}" required="#{required}" 
                         readOnly="#{readOnly}" label="#{msg[id]}:" partialSubmit="#{partialSubmit}" autoSubmit="#{autoSubmit}">
        <mias:items items="#{items}" itemValue="#{itemValue}" itemLabel= "#{itemLabel}"/>
      </tr:selectOneChoice>
    </c:otherwise>
  </c:choose>

</ui:composition>
</tr:document>
